<template>
  <div class="parent-container">
    <el-button type="primary" @click="showDialogUpdate = true">打开修改缴费明细对话框</el-button>
    <el-button type="primary" @click="showDialogCheck = true">打开查看缴费明细对话框</el-button>
    <el-button type="primary" @click="showRemark = true">打开缴费备注对话框</el-button>
    <el-button type="primary" @click="showRefundDialog = true">打开退费申请审核</el-button>
    <el-button type="primary" @click="showRefundDialogInitiate = true">发起退费</el-button>
    <el-button type="primary" @click="showRefundDialogCancel = true">取消退费</el-button>
    <el-button type="primary" @click="showDialogVoucher = true">查看转账凭证</el-button>

    <FeeUpdateDialog
      :visible.sync="showDialogUpdate"
      :form-data="formData"
      :query-params-data="queryParams"
      @confirm="handleFormConfirm"
      @cancel="handleFormCancel"
    ></FeeUpdateDialog>
    <FeeViewDialog
      :visible.sync="showDialogCheck"
      :form-data="formDataCheck"
      :query-params-data="queryParams"
      @confirm="handleFormConfirm"
      @cancel="handleFormCancel"
    ></FeeViewDialog>
    <PaymentRemarks
      :visible="showRemark"
      :title="`缴费单 ${currentPaymentId} `"
      :business-id="currentPaymentId"
      :initial-remark="defaultRemark"
      :max-length="300"
      @submit="handleRemarkSubmit"
      @close="handleRemarkClose"
    ></PaymentRemarks>
    <CheckRefundApplication
      :visible.sync="showRefundDialog"
      :apply-info="refundApplyInfo"
      @submit="handleRefundSubmit"
    ></CheckRefundApplication>
    <InitiateRefundDialog
      :visible.sync="showRefundDialogInitiate"
      :apply-info="refundApplyInfoInitiate"
      @submit="handleRefundSubmitInitiate"
    ></InitiateRefundDialog>
    <CancelRefundDialog
      :visible.sync="showRefundDialogCancel"
      :apply-info="refundApplyInfoCancel"
      @submit="handleRefundSubmitCancel"
    ></CancelRefundDialog>
    <ViewTransferVoucherDialog
      :visible.sync="showDialogVoucher"
      :voucher-data="voucherInfo"
      @confirm-transferred="handleConfirmTransferred"
    ></ViewTransferVoucherDialog>
  </div>
</template>

<script>
import FeeUpdateDialog from "@/components/Payment/FeeUpdateDialog.vue";
import FeeViewDialog from "@/components/Payment/FeeViewDialog.vue";
import PaymentRemarks from "@/components/Payment/PaymentRemarksDialog.vue";
import CheckRefundApplication from "@/components/Payment/CheckRefundApplicationDialog.vue";
import InitiateRefundDialog from "@/components/Payment/InitiateRefundDialog.vue";
import CancelRefundDialog from "@/components/Payment/CancelRefundDialog.vue";
import ViewTransferVoucherDialog from "@/components/Payment/ViewTransferVoucherDialog.vue";

export default {
  components: {
    FeeUpdateDialog,FeeViewDialog,PaymentRemarks,CheckRefundApplication,InitiateRefundDialog,CancelRefundDialog,ViewTransferVoucherDialog
  },
  data() {
    return {
      showDialogUpdate: false,
      formData: {
        // 缴费信息初始值
        paymentStatus: "已缴费",
        paymentMethod: "线上缴费",
        trainingExamFee: "XXX",
        nuoNuoOrderNo: "123456",
        handleSituation: "已办结",
        paymentRemark: "线上缴费备注",
        // 基本信息初始值
        subjectId: "特设培训",
        subjectId2: "特设类别",
        trainingClass: "特设培训班",
        trainingType: "新训",
        name: "张三",
        idType: "idCard",
        idNumber: "123456789012345678",
        idValidDate: [],
        gender: "男",
        personType: "学员",
        birthDate: "2000-01-01",
        nation: "汉",
        duty: "职员",
        qualification: "本科",
        school: "XX大学",
        major: "计算机",
        address: "四川省成都市武侯区",
        zipcode: "610000",
        fax: "028-12345678",
        email: "zhangsan@example.com",
        // 单位信息初始值
        companyName: "XXXX公司",
        creditCode: "123456789123456789",
        contactPhone: "13800138000",
        region: "四川省-成都市-武侯区",
        unitNature: "enterprise",
        remark: "单位备注信息",
      },

      showDialogCheck: false,
      formDataCheck: {
        // 缴费信息初始值
        paymentStatus: "已缴费",
        paymentMethod: "线上缴费",
        trainingExamFee: "XXX",
        nuoNuoOrderNo: "123456",
        paymentVoucher: "http://127.0.0.1:9300/statics/2025/09/19/1_20250919113116A007.png", // 示例：随机图片地址
        isHandled: "已办结",
        paymentRemark: "XXX",
        // 基本信息初始值
        subjectId: "特设培训",
        subjectId2: "特设类别",
        trainingClass: "特设培训班",
        trainingType: "新训",
        name: "张三",
        idType: "idCard",
        idNumber: "123456789012345678",
        idValidDate: [],
        gender: "男",
        personType: "学员",
        birthDate: "2000-01-01",
        nation: "汉",
        duty: "职员",
        qualification: "本科",
        school: "XX大学",
        major: "计算机",
        address: "四川省成都市武侯区",
        zipcode: "610000",
        fax: "028-12345678",
        email: "zhangsan@example.com",
        // 单位信息初始值
        companyName: "XXXX公司",
        creditCode: "123456789123456789",
        contactPhone: "13800138000",
        region: "四川省-成都市-武侯区",
        unitNature: "enterprise",
        remark: "单位备注信息",
      },

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idNumber: null,
        certNumber: null,
        trainingType: null,
        phone: null,
        unitName: null,
        paymentStatus: null,
        recordStatus: null,
        submitStatus: null,
        startTime: null,
        endTime: null,
        projectId: null,
      },

      showRemark: false,               // 控制对话框显示
      currentPaymentId: 'P20231020001', // 当前业务ID
      defaultRemark: '补充缴费信息确认',  // 初始备注内容

      showRefundDialog: false, // 控制对话框显隐
      refundApplyInfo: {
        // 自定义退费申请初始数据
        paymentStatus: "已申请退费",
        paymentMethod: "线上缴费",
        trainingStatus: "未培训",
        examStatus: "未考试",
        name: "张三",
        idCard: "123456789123456789",
        contact: "13800138000",
        unit: "XX科技有限公司",
        applyTime: "2025-09-10 10:30:00",
        applicant: "张三",
        applicantContact: "13800138000",
        registerType: "特设培训",
        registerProject: "安全培训",
        trainingClass: "秋季班",
        trainingType: "新训",
        trainingFee: "1000",
        examFee: "200",
        refundAmount: "800",
        refundReason: "个人原因无法参加",
      },

      showRefundDialogInitiate: false,
      refundApplyInfoInitiate: {
        paymentStatus: "已申请退费",
        paymentMethod: "线上缴费",
        trainingStatus: "未培训",
        examStatus: "未考试",
        name: "张三",
        idCard: "123456789123456789",
        contact: "13800138000",
        unit: "XX科技有限公司",
        applyTime: "2025-09-10 10:30:00",
        applicant: "张三",
        applicantContact: "13800138000",
        registerType: "特设培训",
        registerProject: "安全培训",
        trainingClass: "秋季班",
        trainingType: "新训",
        trainingFee: "1000",
        examFee: "200",
      },
      showRefundDialogCancel: false,
      refundApplyInfoCancel: {
        paymentStatus: "已申请退费",
        paymentMethod: "线上缴费",
        trainingStatus: "未培训",
        examStatus: "未考试",
        name: "张三",
        idCard: "123456789123456789",
        contact: "13800138000",
        unit: "XX科技有限公司",
        applyTime: "2025-09-10 10:30:00",
        applicant: "张三",
        applicantContact: "13800138000",
        registerType: "特设培训",
        registerProject: "安全培训",
        trainingClass: "秋季班",
        trainingType: "新训",
        trainingFee: "1000",
        examFee: "200",
        refundAmount: "800",
        refundReason: "个人原因无法参加",
      },

      showDialogVoucher:false,
      voucherInfo: {
        voucherImg: "http://127.0.0.1:9300/statics/2025/09/19/1_20250919113116A007.png", // 示例图片地址
        uploaderInfo: {
          contactName: "张三",
          contactWay: "12345678910",
          unit: "XXXX公司",
          creditCode: "123456789123456789",
        },
        studentList: [
          {
            studentName: "学员A",
            registerType: "特种设备",
            registerProject: "安全管理",
            trainingClass: "2025春季班",
            trainingType: "新训",
            fee: "500元",
          },
          {
            studentName: "学员B",
            registerType: "特种设备",
            registerProject: "操作技能",
            trainingClass: "2025春季班",
            trainingType: "新训",
            fee: "600元",
          },
        ],
        totalFee: "1100元",
        confirmNames: "学员A、学员B",
      },
    };
  },
  methods: {
    handleFormConfirm(data) {
      console.log('表单提交数据（含缴费、人员、单位信息）:', data.form);
      console.log('查询参数:', data.queryParams);
      this.showDialogUpdate = false;
      this.showDialogCheck = false;
      this.$message.success("修改成功");
    },
    handleFormCancel() {
      console.log('表单已取消');
      this.showDialogUpdate = false;
      this.showDialogCheck = false;
    },
    async handleRemarkSubmit(data) {
      try {
        console.log('父组件接收提交数据:', data)
        // 实际项目中调用API保存备注
        // await this.$api.saveRemark(data)
        this.$message.success('备注已保存')
        this.showRemark = false
      } catch (err) {
        this.$message.error('保存失败：' + err.message)
      }
    },

    // 处理对话框关闭
    handleRemarkClose() {
      this.showRemark = false
    },
    // 供子组件调用的加载历史记录方法（可选）
    async loadRemarkHistory(businessId) {
      try {
        console.log('加载业务ID的备注历史:', businessId)
        // 实际项目中调用API获取数据
        // const res = await this.$api.getRemarkHistory(businessId)
        // return res.data

        // 模拟返回历史数据
        return [
          { time: '2023-10-15 09:30', operator: '张三', content: '初次审核通过' },
          { time: '2023-10-16 14:20', operator: '李四', content: '已完成缴费' }
        ]
      } catch (err) {
        this.$message.error('加载历史记录失败')
        return []
      }
    },


    handleRefundSubmit(submitData) {
      // 处理子组件提交的审核数据（如调用接口保存）
      console.log("退费申请审核结果：", submitData);
      this.$message.success("审核结果提交成功");
    },
    handleRefundSubmitInitiate(submitData) {
      // 处理子组件提交的审核数据（如调用接口保存）
      console.log("退费申请审核结果：", submitData);
      this.$message.success("退费申请已提交");
    },
    handleRefundSubmitCancel(submitData) {
      // 处理子组件提交的审核数据（如调用接口保存）
      console.log("退费申请审核结果：", submitData);
      this.$message.success("取消退费申请已提交");
    },

     handleConfirmTransferred(submitData) {
      console.log("转账信息：", submitData);
    },

  }
};
</script>

<style scoped>
.parent-container {
  padding: 20px;
}
</style>

